package com.java88.springboot04.controller;

import com.java88.springboot04.service.DeptService;
import com.java88.springboot04.service.EmpService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class MyController {
	private DeptService deptService;
	private EmpService empService;

	public MyController(DeptService deptService, EmpService empService) {
		this.deptService = deptService;
		this.empService = empService;
	}

	@RequestMapping("/")
	public String index(
					@RequestParam(required = false) Integer deptno,
					@RequestParam(required = false, defaultValue = "1") int pageNum,
					@RequestParam(required = false, defaultValue = "5") int pageSize,
					ModelMap map) {
		//map.put("str", "这是在Controller方法中保存的字符串值。");
		//map.put("time", new Date());

		map.put("depts", deptService.findAll());
		map.put("pageInfo", empService.findAll(deptno, pageNum, pageSize));
		return "index";
	}
}
